package com.example.demo.controller;

import com.example.demo.entity.Manufacturer;
import com.example.demo.entity.Model;
import com.example.demo.entity.Standard;
import com.example.demo.service.ProductService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/products")
@CrossOrigin(origins = "http://localhost:5173")
public class ProductController {
    private final ProductService productService;

    // 手动注入Service
    public ProductController(ProductService productService) {
        this.productService = productService;
    }

    // API接口方法不变...
    @GetMapping("/manufacturers")
    public ResponseEntity<List<Manufacturer>> getManufacturers() {
        return ResponseEntity.ok(productService.getAllManufacturers());
    }

    @GetMapping("/standards")
    public ResponseEntity<List<Standard>> getStandards() {
        return ResponseEntity.ok(productService.getAllStandards());
    }

    @GetMapping("/models")
    public ResponseEntity<List<Model>> getModels(@RequestParam(required = false) Integer mfrId) {
        return ResponseEntity.ok(productService.getModels(mfrId));
    }
}